package com.exam.bean.paper;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.exam.bean.privilege.Employee;
import com.exam.bean.subject.Question;

/**
 * 试卷答题
 *
 */
@Entity
public class AnswerPaper implements Serializable{
	
	private static final long serialVersionUID = -6354161670906431685L;
	
	private Integer id;
	private Question question;//试题
	private Employee student;//答题人
	private String answer;//作答答案
	private Date createdate=new Date();//作答时间
	private Float score=0f;//得分
	private Employee employee;//改卷教师
	private Date updatedate=new Date();//改卷时间
	private Boolean visible=true;
	
	public AnswerPaper() {}

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
	@JoinColumn(name="answer_id")
	public Question getQuestion() {
		return question;
	}
	public void setQuestion(Question question) {
		this.question = question;
	}

	@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
	@JoinColumn(name="student_id")
	public Employee getStudent() {
		return student;
	}
	public void setStudent(Employee student) {
		this.student = student;
	}

	@Column(length=400,nullable=false)
	public String getAnswer() {
		return answer;
	}
	public void setAnswer(String answer) {
		this.answer = answer;
	}

	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreatedate() {
		return createdate;
	}
	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	@Column(nullable=false)
	public Float getScore() {
		return score;
	}
	public void setScore(Float score) {
		this.score = score;
	}

	@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
	@JoinColumn(name="employee_id")
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	@Temporal(TemporalType.TIMESTAMP)
	public Date getUpdatedate() {
		return updatedate;
	}
	public void setUpdatedate(Date updatedate) {
		this.updatedate = updatedate;
	}

	@Column(nullable=false)
	public Boolean getVisible() {
		return visible;
	}
	public void setVisible(Boolean visible) {
		this.visible = visible;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AnswerPaper other = (AnswerPaper) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
